var QQHttp = cc.Class({


    statics: {
        //QQplay http request
        post: function (url, param,  callback) {
            let self = this;
            let time = false;//是否超时
            let timer = setTimeout(function () {//做请求超时操作
                if (timer == null) {
                    return;
                }
                time = true;
                callback(true);
            }, 10000);
            BK.Http.request({
                url: url,
                method: 'POST',
                headers: {
                    'Cookie':  UserInfo.sessionId
                },
                body: param,
                success: function (succObj) {
                    if(time){
                        return;
                    }

                    UIHelper.hideLoaing();
                    if(succObj.statusCode != 200){
                        let failMsg = HttpUtil.getTextWithStatus(succObj.statusCode);
                        UIHelper.showMsgTips(failMsg,'网络错误','确定')
                        return;
                    }
                    callback(false,succObj);
                },
                fail: function (errObj) {
                    UIHelper.hideLoaing();
                    Log.error(url+'请求失败 ', errObj.msg);
                },
                complete: function () {
                    console.log('complete');
                },
                uploadProgress: function (curr, total) {
                    console.log('upload progress', curr / total);
                },
                downloadProgress: function (curr, total) {
                    console.log('download progress', curr / total);
                }
            });
        },

        get: function (url,  callback) {
            Log.debug("开始QQ的httpget请求"+url)
            let self = this;
            let time = false;//是否超时
            let timer = setTimeout(function () {//做请求超时操作
                if (timer == null) {
                    return;
                }
                time = true;
                callback(true);
            }, 10000);
            Log.debug("开始QQ的httpget请求2")
            BK.Http.request({
                url:url,
                method: 'GET',
                headers: {
                    'Cookie':  UserInfo.sessionId
                },
                success: function (succObj) {
                    if(time){
                        return;
                    }
                    UIHelper.hideLoaing();
                    if(succObj.statusCode != 200){
                        let failMsg = HttpUtil.getTextWithStatus(succObj.statusCode);
                        UIHelper.showMsgTips(failMsg,'网络错误','确定')
                        return;
                    }
                    callback(false,succObj);
                },
                fail: function (errObj) {
                    UIHelper.hideLoaing();
                    Log.error(url+'请求失败 ', errObj.msg);
                },
                complete: function () {
                    console.log('complete');
                },
                uploadProgress: function (curr, total) {
                    console.log('upload progress', curr / total);
                },
                downloadProgress: function (curr, total) {
                    console.log('download progress', curr / total);
                }
            });

        },

    }
});

module.exports = QQHttp;